package common

import "gorm.io/gorm"

type Db interface {
	// 获取单条数据

	// 获取多条数据

	// 获取所有id
}

type mysql struct {
	db *gorm.DB
}

func (d mysql) GetData(table string, filter map[string]interface{}) (result interface{}, err error) {
	tx := d.db.Table(table)
	for k, v := range filter {
		tx.Where("? = ?", k, v)
	}
	err = tx.First(&result).Error
	return nil, err
}

func (d mysql) GetDataS(table string, filter map[string]interface{}) (result []interface{}, err error) {
	tx := d.db.Table(table)
	for k, v := range filter {
		tx.Where("? = ?", k, v)
	}
	err = tx.Find(&result).Error
	return nil, err
}
